package com.xcity.db.entity;
/**
 * 矿
 * @author shipeng.zhu
 */

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.game.map.template.MineTypeTemplate;

import naga.x.App;
import naga.x.game.template.TemplateService;

public class Mine{
//---基本属性 创建时已确定
	private int id;
	private int map;
	private int pos;
	private byte mineType;
	//---占领相关属性 会随时变
	/**
	 * 占领者ID或0
	 */
	private long ownerId;
	/**
	 * 占领时间
	 */
	private long takeTime;
	/**
	 * 占领时为1 每延长一次+1 用于计算结束时间
	 */
	private byte extendCount;
	/**
	 * 上一次领钱时间
	 */
	private long lastTakeTime;
	
	/**
	 * 战斗力
	 */
	private long fightValue;
	
	//---player的属性只缓存不存储
	private String ownerName;
	private int ownerLevel;
	private String ownerIcon;
	private int ownerVipLevel;

	private MineTypeTemplate typeTemp;
	private int battleState = 0;
	private long fightingId = 0;
	private long lastRefreshTime = 0;
	
	public Mine(){}
	public Mine(int map, int pos, int type){
		this.id = map << 8 | pos;
		this.map = map;
		this.pos = pos;
		this.mineType = (byte) type;
		this.ownerId = 0;
		this.takeTime = 0;
		this.extendCount = 0;
		this.lastTakeTime = 0;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getMap() {
		return map;
	}
	public void setMap(int map) {
		this.map = map;
	}
	public int getPos() {
		return pos;
	}
	public void setPos(int pos) {
		this.pos = pos;
	}
	public byte getMineType() {
		return mineType;
	}
	public void setMineType(byte mineType) {
		this.mineType = mineType;
	}
	public long getOwnerId() {
		return ownerId;
	}
	public void setOwnerId(long ownerId) {
		this.ownerId = ownerId;
	}
	public long getTakeTime() {
		return takeTime;
	}
	public void setTakeTime(long takeTime) {
		this.takeTime = takeTime;
	}
	public byte getExtendCount() {
		return extendCount;
	}
	public void setExtendCount(byte extendCount) {
		this.extendCount = extendCount;
	}
	public long getLastTakeTime() {
		return lastTakeTime;
	}
	public void setLastTakeTime(long lastTakeTime) {
		this.lastTakeTime = lastTakeTime;
	}
	public long getFightValue() {
		return fightValue;
	}
	public void setFightValue(long fightValue) {
		this.fightValue = fightValue;
	}
	public String getOwnerName() {
		return ownerName;
	}
//	public void set_ownerName(String _ownerName) {
//		this._ownerName = _ownerName;
//	}
	public int getOwnerLevel() {
		return ownerLevel;
	}
//	public void set_ownerLevel(int _ownerLevel) {
//		this._ownerLevel = _ownerLevel;
//	}
	public String getOwnerIcon() {
		return ownerIcon;
	}
//	public void set_ownerIcon(String _ownerIcon) {
//		this._ownerIcon = _ownerIcon;
//	}
	public int getOwnerVipLevel() {
		return ownerVipLevel;
	}
//	public void set_ownerVipLevel(int _ownerVipLevel) {
//		this._ownerVipLevel = _ownerVipLevel;
//	}
	@JSONField(serialize = false)
	public MineTypeTemplate getTypeTemp(){
		return typeTemp != null?typeTemp : (typeTemp = App.getApp().getServiceManager().get(TemplateService.class).get(MineTypeTemplate.class, mineType));
	}

	@JSONField(serialize = false)
	public int getState(){
		return battleState;
	}
	@JSONField(serialize = false)
	public void setState(int state){
		battleState = state;
	}
	@JSONField(serialize = false)
	public long getFightingId() {
		return fightingId;
	}
	@JSONField(serialize = false)
	public void setFightingId(long fightingId) {
		this.fightingId = fightingId;
	}
	@JSONField(serialize = false)
	public long getLastRefreshTime() {
		return lastRefreshTime;
	}
	@JSONField(serialize = false)
	public void setLastRefreshTime(long lastRefreshTime) {
		this.lastRefreshTime = lastRefreshTime;
	}
	public void end(Player player, long time, int fightValue){
		if(player != null){
			ownerId = player.getId();
			takeTime = time;
			lastTakeTime = time;
			extendCount = 1;
			
			ownerName = player.getName();
			ownerIcon = player.getIcon();
			ownerLevel = player.getLevel();
			ownerVipLevel = player.getVipLvl();
			lastRefreshTime = time;
			this.fightValue = fightValue;
		}else{
			ownerId = 0;
			takeTime = 0;
			lastTakeTime = 0;
			extendCount = 0;
			
			ownerName = null;
			ownerIcon = null;
			ownerLevel = 0;
			ownerVipLevel = 0;
			lastRefreshTime = 0;
		}
	}
	
	public void refreshOwnerInfo(Player player, long time){
		ownerName = player.getName();
		ownerIcon = player.getIcon();
		ownerLevel = player.getLevel();
		ownerVipLevel = player.getVipLvl();
		lastRefreshTime = time;
	}
}
